﻿using Prism.DryIoc;
using Prism.Ioc;
using Prism.Modularity;
using Prism.Services.Dialogs;
using System.Windows;
using WPF.Bill;
using WPF.Core;
using WPF.Core.Services;
using WPF.NoteBook;
using WPF.ToDo;
using WPF.Zero.Services;
using WPF.Zero.ViewModels;
using WPF.Zero.Views;

namespace WPF.Zero
{

    public partial class App : PrismApplication
    {
        protected override Window CreateShell()
        {
           return  Container.Resolve<MainView>();
        }
        // 重写OnInitialized方法
        protected override void OnInitialized()
        {
            // 从容器中解析出IDialogService接口的实现
            var dialog = Container.Resolve<IDialogService>();

            dialog.ShowDialog("HelloView", callback =>
            {
                // 显示LoginView对话框
                dialog.ShowDialog("LoginView", callback =>
                {
                    //判断登录结果，OK就进，NG就退
                    if (callback.Result == ButtonResult.No)
                    {
                        Environment.Exit(0);
                    }
                });
            });
            // 调用基类的OnInitialized方法
            base.OnInitialized();
        }

        protected override void RegisterTypes(IContainerRegistry services)
        {
            //AutoMapper服务
            services.RegisterSingleton<IAppMapper, AppMapper>();

           services.RegisterForNavigation<MainView,MainViewModel>();
            services.RegisterForNavigation<SettingView,SettingViewModel>();
            //数据库服务 
            services.Register<BillService>();
            services.Register<NoteBookService>();
            services.Register<IToDoService, ToDoService>();
            services.Register<INoteBookService,NoteBookService>();
            services.Register<IBillService, BillService>();
            //用户服务
            services.Register<UserService>();
            //登录弹窗
            services.RegisterDialog<LoginView, LoginViewModel>(); 
            //注册弹窗
            services.RegisterDialog<RegisterView, RegisterViewModel>();
            //基于MD组件的弹窗服务
            services.Register<IHostDialogService, HostDialogService>();
            //消息弹窗
            services.RegisterDialog<MsgView, MsgViewModel>();
            //启动页
            services.RegisterDialog<HelloView, HelloViewModel>();
            //菜单导航项
            services.RegisterSingleton<INavigationMenuService, NavigationMenuService>(); 
        }

        protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
        {
            moduleCatalog.AddModule<BillModule>();
            moduleCatalog.AddModule<ToDoModule>();
            moduleCatalog.AddModule<NoteBookModule>();
            base.ConfigureModuleCatalog(moduleCatalog);
        }
    }

}
 